package com.donn.securitycontrolplatform.dutyinfo.controller;


import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.common.entity.dahua.PageDTO;
import com.donn.securitycontrolplatform.dutyinfo.entity.Dutyinfo;
import com.donn.securitycontrolplatform.dutyinfo.service.IDutyinfoService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhenglx
 * @since 2022-06-26
 */
@RestController
@RequestMapping("/scp/api/dutyinfo")
@Tag(name = "DutyinfoController", description = "角色")
public class DutyinfoController {
    @Autowired
    IDutyinfoService dutyinfoService;

    @ApiOperation(value = "新增角色")
    @PostMapping("/add")
    @ResponseBody
    public Result add(@RequestBody @ApiParam(value = "角色对象") Dutyinfo dutyinfo) {

        return dutyinfoService.add(dutyinfo);
    }


    @ApiOperation(value = "修改角色")
    @PostMapping("/update")
    @ResponseBody
    public Result update(@RequestBody @ApiParam(value = "角色对象") Dutyinfo dutyinfo) {

        return dutyinfoService.updateDutyinfo(dutyinfo);
    }


    @ApiOperation(value = "分页查询角色列表")
    @PostMapping("/page")
    @ResponseBody
    public Result getPage(@RequestBody PageDTO<Dutyinfo> pageDto) {
        return dutyinfoService.getPage(pageDto.page());
    }

    @ApiOperation(value = "查询角色列表")
    @GetMapping("/list")
    @ResponseBody
    public Result getList() {
        return Result.success(dutyinfoService.list());
    }


    @ApiOperation(value = "根据角色名称获取角色下所有标签列表")
    @GetMapping("/getTagByDutyinfo")
    @ResponseBody
    public Result getTagByDutyinfo(@RequestParam String name) {
        List<String> tagIds = dutyinfoService.getTagByDutyinfo(name);
        return Result.success(tagIds);
    }


    @ApiOperation(value = "删除角色")
    @DeleteMapping("/delete")
    @ResponseBody
    public Result delete(@RequestParam Integer id) {

        return dutyinfoService.deleteById(id);
    }
}
